/*
 * Name: $RCSfile: ParameterFactory.java,v $
 * Version: $Revision: 1.1 $
 * Date: $Date: Oct 31, 2011 2:45:36 PM $
 *
 * Copyright (C) 2011 COMPANY_NAME, Inc. All rights reserved.
 */

package com.toidep.api;

import java.io.UnsupportedEncodingException;

import com.toidep.config.Constants;
import com.toidep.utilities.StringUtility;

/**
 * ParameterFactory class builds parameters for web service apis
 * 
 * @author Lemon
 */
public final class ParameterFactory {

	public static String encode(String value) throws UnsupportedEncodingException {
		if (value != null) {
			return StringUtility.encode(value);
		} else {
			return "";
		}
	}

	/******************* APIs ***********************/
	
	/**
	 * Login url 
	 * @param username
	 * @param password
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	public static String createURLLogin(String username, String password) throws UnsupportedEncodingException {
		String module = encode("Login");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_RESPONSE_USER_NAME + "=" + username +
				"&" + Constants.PARAM_RESPONSE_PASSWORD + "=" + password;
	}
	
	// GET LIST NEWS IN HOME PAGE
	public static String createURLGetHomeDetail() throws UnsupportedEncodingException {
		String module = encode("GetHomeDetail");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module;
	}
	
	/**
	 * Tao URL lay danh sach Nguoi mau theo type
	 * @param type
	 * @param page
	 * @param pageSize
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetModels(int type, int page, int pageSize) throws UnsupportedEncodingException {
		String module = encode("getModel");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_TYPE + "=" + type +
				"&" + Constants.PARAM_REQUEST_PAGE + "=" + page +
				"&" + Constants.PARAM_REQUEST_PAGE_SIZE + "=" + pageSize;
	}
	
	/**
	 * Tao URL lay thong tin chi tiet cua Nguoi mau
	 * @param model_id
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetModelDetail(String model_id) throws UnsupportedEncodingException {
		String module = encode("GetModelDetail");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_MODEL_ID + "=" + model_id;
	}
	
	/**
	 * Tao URL lay profile cua Nguoi mau
	 * @param model_id
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetModelProfile(String model_id) throws UnsupportedEncodingException {
		String module = encode("GetProfile");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_MODEL_ID_2 + "=" + model_id;
	}
	
	/**
	 * Tao URL lay cac comments
	 * @param typeComment = 1: Model | 2: Album | 3: Video
	 * @param id
	 * @param page
	 * @param pageSize
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetComments(int typeComment, String id, int page, int pageSize) throws UnsupportedEncodingException {
		String module = encode("getComment");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_TYPE + "=" + typeComment +
				"&" + Constants.PARAM_REQUEST_ID + "=" + id + 
				"&" + Constants.PARAM_REQUEST_PAGE + "=" + page + 
				"&" + Constants.PARAM_REQUEST_PAGE_SIZE + "=" + pageSize ;
	}
	
	/**
	 * Tao URL lay danh sach Video Normal
	 * Neu modelId=0 la lay ALL
	 * @param typeVideo = 0: ALL / 1: NEW / 2: HOT / 3: TOP
	 * @param page
	 * @param pageSize
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetVideosNormal(int typeVideo, int page, int pageSize) throws UnsupportedEncodingException {
		String module = encode("GetVideos");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_TYPE + "=" + typeVideo +
				"&" + Constants.PARAM_REQUEST_PAGE + "=" + page +
				"&" + Constants.PARAM_REQUEST_PAGE_SIZE + "=" + pageSize;
	}
	
	/**
	 * Tao URL lay danh sach Video cua 1 model
	 * @param modelId
	 * @param page
	 * @param pageSize
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetVideosOfModel(String modelId, int page, int pageSize) throws UnsupportedEncodingException {
		String module = encode("GetVideos");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_MODEL_ID_2 + "=" + modelId +
				"&" + Constants.PARAM_REQUEST_PAGE + "=" + page +
				"&" + Constants.PARAM_REQUEST_PAGE_SIZE + "=" + pageSize;
	}
	
	/**
	 * Tao URL lay chi tiet cua 1 video
	 * @param modelId
	 * @param page
	 * @param pageSize
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetVideoDetail(String videoId, String token) throws UnsupportedEncodingException {
		String module = encode("getVideoDetail");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_ID + "=" + videoId +
				"&" + Constants.PARAM_REQUEST_ACCESS_TOKEN + "=" + token;
	}
	
	/**
	 * Tao URL lay chi tiet cua 1 tin tuc
	 * @param newId
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetNewDetail(String newId) throws UnsupportedEncodingException {
		String module = encode("GetArticleDetail");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_ID + "=" + newId;
	}
	
	/**
	 * Tao URL lay profile cua Nguoi mau
	 * @param model_id
	 * Tao URL lay danh sach Albums Normal
	 * @param typeAlbum = 0: ALL / 1: NEW / 2: HOT / 3: TOP
	 * @param page
	 * @param pageSize
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetAlbumsNormal(int typeAlbum, int page, int pageSize) throws UnsupportedEncodingException {
		String module = encode("GetAlbums");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_TYPE + "=" + typeAlbum +
				"&" + Constants.PARAM_REQUEST_PAGE + "=" + page +
				"&" + Constants.PARAM_REQUEST_PAGE_SIZE + "=" + pageSize;
	}
	
	/**
	 * Tao URL lay danh sach Albums cua Model
	 * @param modelId
	 * @param page
	 * @param pageSize
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetAlbumsOfModel(String modelId, int page, int pageSize) throws UnsupportedEncodingException {
		String module = encode("GetAlbums");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_MODEL_ID_2 + "=" + modelId +
				"&" + Constants.PARAM_REQUEST_PAGE + "=" + page +
				"&" + Constants.PARAM_REQUEST_PAGE_SIZE + "=" + pageSize;
	}
	
	/**
	 * Tao URL lay thong tin chi tiet cua Album
	 * @param album_id
	 * @param token 
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetAlbumDetail(String album_id, String token) throws UnsupportedEncodingException {
		String module = encode("GetAlbumDetail");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_ID + "=" + album_id +
				"&" + Constants.PARAM_REQUEST_ACCESS_TOKEN + "=" + token;
	}
	
	/**
	 * Tao URL lay danh sach Tin tuc, Cau chuyen, Su kien Normal
	 * @param type = 1: Tin tuc | = 2: Cau chuyen | = 3: Su kien
	 * @param page
	 * @param pageSize
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetArticlesNormal(int type, int page, int pageSize) throws UnsupportedEncodingException {
		String module = encode("GetArticle");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_TYPE + "=" + type +
				"&" + Constants.PARAM_REQUEST_PAGE + "=" + page +
				"&" + Constants.PARAM_REQUEST_PAGE_SIZE + "=" + pageSize;
	}
	
	/**
	 * Tao URL lay danh sach Tin tuc, Cau chuyen, Su kien cua Model
	 * @param type = 1: Tin tuc | = 2: Cau chuyen | = 3: Su kien
	 * @param modelId
	 * @param page
	 * @param pageSize
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetArticlesOfModel(int type, String modelId, int page, int pageSize) throws UnsupportedEncodingException {
		String module = encode("GetArticle");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_TYPE + "=" + type +
				"&" + Constants.PARAM_REQUEST_MODEL_ID + "=" + modelId +
				"&" + Constants.PARAM_REQUEST_PAGE + "=" + page +
				"&" + Constants.PARAM_REQUEST_PAGE_SIZE + "=" + pageSize;
	}

	public static String createURLGetRelation(int type, String id, int page, int pageSize) throws UnsupportedEncodingException {
		String module = encode("GetRelation");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_TYPE + "=" + type +
				"&" + Constants.PARAM_REQUEST_ID + "=" + id +
				"&" + Constants.PARAM_REQUEST_PAGE + "=" + page +
				"&" + Constants.PARAM_REQUEST_PAGE_SIZE + "=" + pageSize;
	}
	
	/**
	 * Tim kiem noi dung theo content va type
	 * @param typeSearch 1: Model | 2: Video | 3: Album | 4: News | 5: Story | 6: Event
	 * @param keyword
	 * @param page
	 * @param pageSize
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String createURLGetSearchContent(int typeSearch, String keyword, int page, int pageSize) throws UnsupportedEncodingException {
		String module = encode("Search");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_TYPE + "=" + typeSearch +
				"&" + Constants.PARAM_REQUEST_KEYWORD + "=" + encode(keyword) +
				"&" + Constants.PARAM_REQUEST_PAGE + "=" + page +
				"&" + Constants.PARAM_REQUEST_PAGE_SIZE + "=" + pageSize;
	}
	
	/**
	 * Post Comment
	 * @param string 
	 * @param comment 
	 * @param objId 
	 * @param commentType 
	 */
	public static String createURLPostComment(int commentType, String objId, String comment, String access_token) throws UnsupportedEncodingException {
		String module = encode("Comment");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_TYPE + "=" + commentType +
				"&" + Constants.PARAM_REQUEST_ID + "=" + objId +
				"&" + Constants.PARAM_REQUEST_COMMENT + "=" + encode(comment) +
				"&" + Constants.PARAM_REQUEST_ACCESS_TOKEN + "=" + access_token;
	}
	
	/**
	 * Get Free list
	 */
	public static String createURLGetFree() throws UnsupportedEncodingException {
		String module = encode("free");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module;
	}
	
	/**
	 * Get Update list
	 */
	public static String createURLGetUpdate(int page, int pageSize) throws UnsupportedEncodingException {
		String module = encode("update");
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_PAGE + "=" + page +
				"&" + Constants.PARAM_REQUEST_PAGE_SIZE + "=" + pageSize;
	}

	public static String createURLSubScribe() {
		String module = "subScribe";
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module;
	}

	public static String createURLChargeBySub() {
		String module = "subScribeReg";
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module;
	}

	public static String createURLChargeByCard() {
		String module = "chargeCardReg";
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module;
	}

	public static String createURLChangePhoneNumber() {
		String module = "editPhoneNumber";
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module;
	}

	public static String createURLGetEmails(String accessToken, int page, int pageSize) {
		String module = "GetListEmail";
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_ACCESS_TOKEN + "=" + accessToken +
				"&" + Constants.PARAM_REQUEST_PAGE + "=" + page +
				"&" + Constants.PARAM_REQUEST_PAGE_SIZE + "=" + pageSize;
	}

	public static String createURLGetDetailEmails(String accessToken, String emailId) {
		String module = "GetDetailEmail";
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_ACCESS_TOKEN + "=" + accessToken +
				"&" + Constants.PARAM_REQUEST_EMAIL_ID + "=" + emailId ;
	}
	public static String createURLGetPointUser(String accessToken) {
		String module = "GetPointUser";
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_ACCESS_TOKEN + "=" + accessToken;
	}

	public static String createURLGetHistory(String accessToken) {
		String module = "GetHistory";
		
		return Constants.APP_DOMAIN + Constants.API_PATH + module +
				"?" + Constants.PARAM_REQUEST_ACCESS_TOKEN + "=" + accessToken;
	}
	
}
